package com.mid;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lxk on 2019/5/12.
 */
public class Solution98 {

    void inorderVisit(TreeNode curNode, List res) {
        if (curNode == null) {
            return;
        }
        inorderVisit(curNode.left, res);
        res.add(curNode.val);
        inorderVisit(curNode.right, res);
    }

    public boolean isValidBST(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        inorderVisit(root, list);
        if (list.size() == 1 || list.size() == 0) {
            return true;
        }
        for (int i = 0; i < list.size() - 2; i++) {
            if (list.get(i) > list.get(i + 1)) {
                return false;
            }
        }
        return true;
    }

}
